package com.example.springboot_vue.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springboot_vue.common.PageDto;
import com.example.springboot_vue.entity.Goods;
import com.example.springboot_vue.entity.Goodstype;
import com.example.springboot_vue.mapper.GoodsMapper;
import com.example.springboot_vue.service.GoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sgp
 * @since 2024-07-19
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;
    @Override
    public PageDto<Goods> selectAll(Goods goods) {
        QueryWrapper<Goods> queryWrapper = new QueryWrapper<>();
        if(ObjectUtils.isNotEmpty(goods.getName())){
            queryWrapper.lambda().like(Goods::getName,goods.getName());
        }
        if(ObjectUtils.isNotEmpty(goods.getStorage())){
            queryWrapper.lambda().eq(Goods::getStorage,goods.getStorage());
        }
        if(ObjectUtils.isNotEmpty(goods.getGoodstype())){
            queryWrapper.lambda().eq(Goods::getGoodstype,goods.getGoodstype());
        }
        Page<Goods> page = new Page<>(goods.getPage(), goods.getSize());
        Page<Goods> selectPage = goodsMapper.selectPage(page, queryWrapper);
        PageDto<Goods> pageDto = new PageDto<>();
        pageDto.setTotal(selectPage.getTotal());
        pageDto.setList(selectPage.getRecords());
        return pageDto;
    }
}
